package main

import (
	"fmt"
)

/*不带参数的函数 没有返回值*/
func hello() {
	fmt.Println("helloWorld")
}

/*带参数的函数 没有返回值*/
func inputData(a int) {
	fmt.Println("输入的数据是:", a)
}

//可变参数
func inputMutiData(a ...int) {
	for i, v := range a {
		fmt.Println("index:", i, "value:", v)
	}
}

/**函数返回多个值*/
func swap(a, b int) (int, int) {
	return b, a
}

func testSwap() {
	a := 23
	b := 34
	fmt.Println("a=", a, "b=", b)
	a, b = swap(a, b)
	fmt.Println("a=", a, "b=", b)
}

//计算平均成绩
func averageScore(scores []float64) (average float64) {
	l := len(scores)
	sum := 0.0
	for _, v := range scores {
		sum += v
	}
	average = sum / float64(l)
	return
}

func testAverageScore() {
	scores := []float64{67.4, 89.4, 90.4, 89.5, 90, 80}
	average := averageScore(scores)
	fmt.Println("average=", average)
}

func main() {
	hello()
	inputData(200)
	inputMutiData(2, 3, 4, 5, 67, 54)
	testSwap()
	testAverageScore()
	testInc()

}

func testInc() {
	nextEven := makeEvenGenerator()
	fmt.Println("next:", nextEven()) // 0
	fmt.Println("next:", nextEven()) // 2
	fmt.Println("next:", nextEven()) // 4
}

//闭包
func makeEvenGenerator() func() uint {
	i := uint(0)
	return func() (ret uint) {
		ret = i
		i += 2
		return
	}
}
